package com.ns.school.service.wave.impl;

import com.ns.school.common.utils.JsonUtil;
import com.ns.school.mapper.wave.WaveDeviceMapper;
import com.ns.school.po.edu.BookDB;
import com.ns.school.po.edu.LayuiResult;
import com.ns.school.po.wave.WaveDevicePO;
import com.ns.school.po.wave.WaveStationPO;
import com.ns.school.service.base.BaseService;
import com.ns.school.service.wave.WaveDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class WaveDeviceServiceImpl extends BaseService implements WaveDeviceService {
    @Autowired
    private WaveDeviceMapper waveDeviceMapper;

    @Override
    public void findAll(WaveDevicePO waveDevicePO) {
        List<WaveDevicePO> list =waveDeviceMapper.findAllDevices(waveDevicePO);

        log.info(JsonUtil.toStr(list));
        Map<Integer,WaveDevicePO> map = new HashMap<>();
        for (WaveDevicePO waveDevicePO1 : list) {
            map.put(waveDevicePO1.getId(),waveDevicePO1);
        }

        for(Map.Entry<Integer,WaveDevicePO> entry:map.entrySet()){
            System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
        }
    }

    @Override
    public List<WaveDevicePO> findAllDevices(WaveDevicePO waveDevicePO) {
        return waveDeviceMapper.findAllDevices(waveDevicePO);
    }

    @Override
    public void addDevices(WaveDevicePO waveDevicePO, LayuiResult<WaveDevicePO> result) {
        Date date = new Date();
        waveDevicePO.setCreateTime(date);
        Integer addDevice=waveDeviceMapper.addDevice(waveDevicePO);
        if(addDevice>0){
            result.setCode(0);
            result.setMsg("添加成功");
        }
    }

    @Override
    public WaveDevicePO selectDevice(Integer id) {
        return waveDeviceMapper.selectDevice(id);
    }

    @Override
    public Integer updateDevice(WaveDevicePO waveDevicePO) {
        return waveDeviceMapper.updeteDevice(waveDevicePO);
    }

    @Override
    public void delDevice(LayuiResult result, WaveDevicePO params) {

        if(waveDeviceMapper.delDevice(params)==0){
            result.setMsg("删除失败");

        }
        result.setMsg("删除成功");

    }

    @Override
    public Integer delDeviceAll(Integer ids) {

        return waveDeviceMapper.delDeviceAll(ids);

    }
}
